const Koa = require('koa')
const bodyParser = require('koa-bodyparser')
const userRouter = require('../router/user.router')
const loginRouter = require('../router/login.router')
const listRouter = require('../router/list.router')
const tagRouter = require('../router/tag.router')
const searchRouter = require('../router/search.router')


const cors = require('@koa/cors')
const collectRouter = require('../router/collect.router')
const detailRouter = require('../router/detail.router')
const fileRouter = require('../router/file.router')
const profileRouter = require('../router/profile.router')
const orderRouter = require('../router/order,router')
// 创建koa实列
const app = new Koa()

app.use(cors({
  origin: '*',
  allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
  allowHeaders: ['Content-Type', 'Authorization'],
  exposeHeaders: ['Authorization'],
  credentials: true,
}))

app.use(bodyParser())
app.use(userRouter.routes())
app.use(userRouter.allowedMethods())
app.use(loginRouter.routes())
app.use(loginRouter.allowedMethods())
app.use(tagRouter.routes())
app.use(tagRouter.allowedMethods())
app.use(listRouter.routes())
app.use(listRouter.allowedMethods())
app.use(searchRouter.routes())
app.use(searchRouter.allowedMethods())
app.use(collectRouter.routes())
app.use(collectRouter.allowedMethods())
app.use(detailRouter.routes())
app.use(detailRouter.allowedMethods())
app.use(fileRouter.routes())
app.use(fileRouter.allowedMethods())
app.use(profileRouter.routes())
app.use(profileRouter.allowedMethods())
app.use(orderRouter.routes())
app.use(orderRouter.allowedMethods())


module.exports = app